import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_tutorial/app/modules/home/home_binding.dart';
import 'package:getx_tutorial/app/modules/home/home_page.dart';
import 'package:getx_tutorial/app/modules/mine/mine_page.dart';
import 'package:getx_tutorial/app/modules/route/route_page.dart';
import 'package:getx_tutorial/app/modules/state/state_page.dart';
import 'package:getx_tutorial/app/routes/app_pages.dart';

class IndexController extends GetxController {
  var currentIndex = 1.obs;

  // 底部导航菜单
  List<BottomNavigationBarItem> bottomNavItems = [
    BottomNavigationBarItem(
      icon: const Icon(Icons.home),
      label: '首页'
    ),
    BottomNavigationBarItem(
      icon: const Icon(Icons.pages),
      label: '路由'
    ),
    BottomNavigationBarItem(
      icon: const Icon(Icons.star),
      label: '状态'
    ),
    BottomNavigationBarItem(
      icon: const Icon(Icons.person),
      label: '我的'
    ),
  ];

  // 导航页面
  final pages = [
    Routes.HOME,
    Routes.ROUTE,
    Routes.STATE,
    Routes.MINE
  ];

  void changePage(int index) {
    currentIndex.value = index;
    Get.toNamed(pages[index], id: 1);
  }

  Route? onGenerateRoute(RouteSettings settings) {
    if (settings.name == Routes.HOME) {
      return GetPageRoute(
        settings: settings,
        page: () => HomePage(),
        binding: HomeBinding()
      );
    } else if (settings.name == Routes.ROUTE) {
      return GetPageRoute(
        settings: settings,
        page: () => RoutePage()
      );
    } else if (settings.name == Routes.STATE) {
      return GetPageRoute(
        settings: settings,
        page: () => StatePage()
      );
    } else if (settings.name == Routes.MINE) {
      return GetPageRoute(
        settings: settings,
        page: () => MinePage()
      );
    } else {
      return null;
    }
  }
  
}